package com.itheima.question.controller;

import com.itheima.PageVo;
import com.itheima.Result;
import com.itheima.admin.dto.PageDto;
import com.itheima.question.dto.QuestionDto;
import com.itheima.question.service.IQuestionService;
import com.itheima.question.vo.QuestionPageVo;
import com.itheima.question.vo.QuestionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/question")
@Api(value = "管理后台答题模块接口", tags = "question", description = "用于实现后台题目的增删改查操作")

public class QuestionController {

    @Autowired
    private IQuestionService questionService;

    @PostMapping("/add")
    @ApiOperation("添加题目")
    public Result addQuestion(@RequestBody QuestionDto questionDto){
       boolean result = questionService.addQuestion(questionDto);
       return new Result(result,result?"添加成功":"添加失败",null);
    }

    @PostMapping("/list")
    @ApiOperation("分页查询题目")
    public PageVo<QuestionPageVo> queryByPage(@RequestBody PageDto pageDto){
        return questionService.queryByPage(pageDto);
    }


    @GetMapping("/{id}")
    @ApiOperation("根据id查询题目")
    public QuestionVo queryById(@PathVariable String id){
        return questionService.queryById(id);
    }
}
